import { defineAsyncComponent } from "vue"
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

export default {
  install(app) {
    const components = import.meta.glob("./*/index.vue")
    // 遍历组件模块实现自动注册
    for (const [key, value] of Object.entries(components)) {
      // 拼接组件注册的 name
      const componentName = key.replace("./", "").split("/")[0]
      // 通过 defineAsyncComponent 异步导入指定路径下的组件
      app.component(componentName, defineAsyncComponent(value))
    }

    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
      app.component(key, component)
    }
  },
}
